<template>
	<view class="login-container">
		<!-- 顶部背景 -->
		<view class="bg-top">
			<image src="/static/images/share.png" mode="aspectFill"></image>
		</view>
		
		<!-- Logo -->
		<view class="logo">
			<image src="/static/share.png" mode="aspectFit"></image>
			<text class="title">鑫汇园包装材料</text>
		</view>
		
		<!-- 登录按钮 -->
		<view class="login-box">
			<view class="login-btn" @click="login_weixin">
				<text class="icon iconfont icon-weixin"></text>
				<text>微信一键登录</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {}
		},
		methods: {
			login_weixin() {
				let that = this;
				vk.userCenter.loginByWeixin({
					success: (data) => {
						vk.toast("登录成功");
						setTimeout(() => {
							// 跳转到首页,或页面返回
							that.login_success(data);
						}, 1000);
					}
				});
			},
			// 登录成功后的回调
			login_success(data) {
				// 获取来源页
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				
				if(prevPage) {
					// 有来源页就返回
					vk.navigateBack();
				} else {
					// 没有来源页就跳转到首页
					vk.navigateTo({
						url: '/pages/index/index'
					});
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.login-container {
	min-height: 100vh;
	background-color: #fff;
	position: relative;
	
	.bg-top {
		width: 100%;
		height: 400rpx;
		overflow: hidden;
		
		image {
			width: 100%;
			height: 100%;
		}
	}
	
	.logo {
		position: absolute;
		top: 200rpx;
		left: 50%;
		transform: translateX(-50%);
		display: flex;
		flex-direction: column;
		align-items: center;
		
		image {
			width: 160rpx;
			height: 160rpx;
			border-radius: 40rpx;
			box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.1);
		}
		
		.title {
			font-size: 40rpx;
			color: #333;
			font-weight: bold;
			margin-top: 30rpx;
		}
	}
	
	.login-box {
		position: absolute;
		left: 50%;
		bottom: 200rpx;
		transform: translateX(-50%);
		width: 100%;
		padding: 0 60rpx;
		display: flex;
		flex-direction: column;
		align-items: center;
		
		.login-btn {
			width: 100%;
			height: 90rpx;
			background: #07c160;
			border-radius: 45rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			color: #fff;
			font-size: 32rpx;
			
			.icon {
				font-size: 40rpx;
				margin-right: 12rpx;
			}
			
			&:active {
				opacity: 0.8;
			}
		}
		
		.tips {
			font-size: 24rpx;
			color: #999;
			margin-top: 30rpx;
		}
	}
}
</style>